package com.heima.tlias.service.impl;

import com.heima.tlias.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Service
@RequiredArgsConstructor
public class FileServiceImpl implements FileService {

    //private final OssTemplate ossTemplate;

    @Override
    public String upload(MultipartFile file) throws IOException {
        //1. 获取原始文件名称
        String originalFilename = file.getOriginalFilename();
        //2. 生成唯一文件名
        String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
        //生成多层级目录,方便文件管理
        filename = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))+"/"+filename;
        //上传文件到阿里云oss
        //String readPath = ossTemplate.upload(filename, file.getInputStream());

        return null;
    }
}
